#show-book
  .header
    %span.image= image_tag @book.image_url() if @book.image?
    %span.title= truncate(@book.name, length: 80)
    %span.link
      - if current_user.admin?
        = link_to t('.edit'), edit_book_path(@book)
      - else
        = link_to t('.borrow'), new_book_transaction_path(book_id: @book.id, user_id: current_user.id)
      = '|'
      = link_to t('.back'), books_path
      - if current_user.admin?
        = '|'
        = link_to t('.transactions'), book_transactions_path(book_id: @book.id)

  %table.book_info_table.table-striped
    %tr
      %th= t('.title')
      %td= @book.name
    %tr
      %th= t('.author')
      %td= @book.author
    %tr
      %th= t('publisher')
      %td= @book.publisher
    %tr
      %th= t('publish_date')
      %td= @book.publish_date
    %tr
      %th= t('description')
      %td= simple_format(@book.description)
    %tr
      %th= t('category')
      %td= @book.category.try(:name)
    %tr
      %th= t('.number_of_rate')
      %td= @book.rates.count
    %tr
      %th= t('.rating_average')
      %td= ratings_for @book, :static

  .rate_btn
    %span
      = t('.your_rate')
      %span.rating_stars
      - if (@book.is_rated_by?(current_user))
        = ratings_for @book, show_user_rating: true
      - else
        = ratings_for @book

  .comments_list
    .past_comments
      - if @comments.blank?
        = t('.no_comment_yet')
      - else
        %ul
          - @comments.each do |comment|
            %li.comment{comment_id: comment.id}
              .title= comment.title.blank? ? t('.no_title') : comment.title
              .user= "#{t('.by')} #{comment.user.try(:name)}"
              .created_at= "#{t('.at')} #{comment.created_at.strftime("%I:%M%p - %d/%m/%Y")}"
              .message= comment.comment.blank? ? t('.no_comment') : simple_format(comment.comment)
    .input_comment
      = form_tag comment_book_path do
        = text_field_tag :title, "", class: "input-block-level", placeholder: t('.title')
        = text_area_tag :comment, "", class: "input-block-level", placeholder: t('.message')
        .submit_btn= submit_tag t('.submit')

